package com.zsf.xml;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;

public class XmlParserActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		InputStream xml = this.getClass().getClassLoader()
				.getResourceAsStream("data1.xml");
		Page page = ParserUtility.getPage(xml);
		System.out.println(page);
//		List<Node> nodeList = ParserUtility.getNodeList(xml);
//		for(Node node:nodeList)
//			System.out.println(node);
//		InputStream xml = this.getClass().getClassLoader()
//				.getResourceAsStream("test.xml");
//		List<Person> personList;
//		try {
//			personList = ParserUtility.getPersons(xml);
//			for(Person person:personList)
//				System.out.println(person);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		InputStream xml = this.getClass().getClassLoader()
//				.getResourceAsStream("person.xml");
//		List<River> riverList = ParserUtility.parse(xml);
//		for (River river : riverList)
//			System.out.println(river);
	}

	public static byte[] read(InputStream inStream) {
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = 0;
		try {
			while ((len = inStream.read(buffer)) != -1) {
				outStream.write(buffer, 0, len);
			}
			inStream.close();
			return outStream.toByteArray();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

}